﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc.Ajax;

namespace FindPharmacies.Model
{
    public class SqlPharmacyRepository : IPharmacyRepository
    {
        DB db;
        public SqlPharmacyRepository()
        {
            db = new DB();
        }

        public IQueryable<Pharmacy> FindAllPharmacies()
        {
            return db.Pharmacies;
        }

        public Pharmacy GetPharmacy(int id)
        {
            return db.Pharmacies.SingleOrDefault(x => x.PharmacyID == id);
        }

        public void Add(Pharmacy pharmacy)
        {
            db.Pharmacies.InsertOnSubmit(pharmacy);
        }

        public void Update(Pharmacy pharmacy)
        {
            db.SubmitChanges();
        }

        public void Delete(Pharmacy pharmacy)
        {
            db.Pharmacies.DeleteOnSubmit(pharmacy);
            db.SubmitChanges();
        }
    }
}